import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
import { FastifyAdapter, NestFastifyApplication } from '@nestjs/platform-fastify';

async function bootstrap() {
  const app = await NestFactory.create<NestFastifyApplication>(
    AppModule,
    new FastifyAdapter()
  );

  // 设置全局路由前缀为api
  app.setGlobalPrefix('api');

  // 配置Swagger
  const config = new DocumentBuilder()
    .setTitle('示例API')
    .setDescription('这是一个使用NestJS和Swagger的示例API')
    .setVersion('1.0')
    .build();

  const document = SwaggerModule.createDocument(app, config);
  // 设置Swagger文档路径为/api，与控制器前缀一致
  SwaggerModule.setup('api-docs', app, document);

  const port = 3000;
  await app.listen({ port, host: '0.0.0.0' });
  console.log(`应用程序运行在: http://localhost:${port}`);
  console.log(`Swagger文档地址: http://localhost:${port}/api-docs`);
}
bootstrap();